package com.example.wangning.mycarofcountry.forum.lecturer;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.mycarofcountry.entity.dao.Forum_total;
import com.example.wangning.mycarofcountry.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/15.
 */
public class LecturerAdapter extends RecyclerView.Adapter<LecturerAdapter.TotalViewHolder>{
    private List<Forum_total> data;
    private Context context;

    public LecturerAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }
    public void addData(List<Forum_total> datas){
        data = datas;
        notifyDataSetChanged();
    }

    @Override
    public TotalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.list_item_total,null);
        return new TotalViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TotalViewHolder holder, int position) {
        if (data != null && data.size() > 0){
            Forum_total totallist = data.get(position);
            holder.title.setText(totallist.getTitle());
            holder.replycount.setText(String.valueOf(totallist.getReplycounts()));
            holder.lastreplydate.setText(totallist.getLastreplydate());
            holder.bbsname.setText(totallist.getBbsname());
        }

    }

    @Override
    public int getItemCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }


    class TotalViewHolder extends RecyclerView.ViewHolder {
            TextView title, lastreplydate, bbsname, replycount;

            public TotalViewHolder(View view) {
                super(view);
                title = (TextView) view.findViewById(R.id.titleTv);
                lastreplydate = (TextView) view.findViewById(R.id.typenameTv);
                bbsname = (TextView) view.findViewById(R.id.timeTv);
                replycount = (TextView) view.findViewById(R.id.typeTv);
            }

        }
    }

